package com.xrit.ssm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xrit.ssm.dao.UserDao;
import com.xrit.ssm.entity.QueryPageBean;
import com.xrit.ssm.pojo.UserInfo;
import com.xrit.ssm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 类名称: UserServiceImpl
 * 类描述:TODO
 * 创建人: czb
 * 创建时间:2022/8/11 下午 03:24
 * Version 1.0.0
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public UserInfo findByUserName(String username) {
        return userDao.findByUserName(username);
    }

    @Override
    public List<UserInfo> findAll() {
        return userDao.findAll();
    }

    @Override
    public PageInfo<UserInfo> findPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        if (!StringUtils.isEmpty(queryPageBean.getQueryString())){
            queryPageBean.setQueryString("%"+queryPageBean.getQueryString()+"%");
        }
       List<UserInfo> list= userDao.findPage(queryPageBean.getQueryString());
        return new PageInfo<>(list);
    }
}
